package com.sugon.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.RandomUtil;
import com.sugon.dao.ToolsControlWayDao;
import com.sugon.entity.ToolsControlWayEntity;
import com.sugon.service.ToolsControlWayService;
import com.sugon.utils.Constant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.sugon.utils.ShiroUtils.getUserId;

/**
 * 管控方式Service实现类
 *
 * @author sugon
 * @date 2019-08-01 09:46:35
 */
@Service("toolsControlWayService")
public class ToolsControlWayServiceImpl implements ToolsControlWayService {

    @Autowired
    private ToolsControlWayDao toolsControlWayDao;

    /**
     * queryObjectByControlCode
     *
     * @param controlCode 管控代码
     * @return
     */
    @Override
    public ToolsControlWayEntity queryObjectByControlCode(String controlCode) {
        Map<String, Object> queryParam = new HashMap<>(1);
        queryParam.put("controlCode", controlCode);
        List<ToolsControlWayEntity> toolsControlWayList = queryList(queryParam);
        return CollectionUtil.isNotEmpty(toolsControlWayList) ? toolsControlWayList.get(0) : null;
    }

    /**
     * queryObject
     *
     * @param id 主键
     * @return
     */
    @Override
    public ToolsControlWayEntity queryObject(String id) {
        return toolsControlWayDao.queryObject(id);
    }

    /**
     * queryList
     *
     * @param map 参数
     * @return
     */
    @Override
    public List<ToolsControlWayEntity> queryList(Map<String, Object> map) {
        return toolsControlWayDao.queryList(map);
    }

    /**
     * queryTotal
     *
     * @param map 参数
     * @return
     */
    @Override
    public int queryTotal(Map<String, Object> map) {
        return toolsControlWayDao.queryTotal(map);
    }

    /**
     * save
     *
     * @param toolsControlWay 实体
     * @return
     */
    @Override
    public int save(ToolsControlWayEntity toolsControlWay) {
        toolsControlWay.setId(RandomUtil.randomString(32));
        toolsControlWay.setCreateTime(new Date());
        toolsControlWay.setCreateUser(getUserId());
        toolsControlWay.setDelFlag(Integer.valueOf(Constant.IS_NOT_DEL));
        return toolsControlWayDao.save(toolsControlWay);
    }

    /**
     * update
     *
     * @param toolsControlWay 实体
     * @return
     */
    @Override
    public int update(ToolsControlWayEntity toolsControlWay) {
        toolsControlWay.setUpdateTime(new Date());
        toolsControlWay.setUpdateUser(getUserId());
        return toolsControlWayDao.update(toolsControlWay);
    }

    /**
     * delete
     *
     * @param id
     * @return
     */
    @Override
    public int delete(String id) {
        return toolsControlWayDao.delete(id);
    }

    /**
     * deleteBatch
     *
     * @param ids
     * @return
     */
    @Override
    public int deleteBatch(String[] ids) {
        return toolsControlWayDao.deleteBatch(ids);
    }
}
